import service from "@/services/request";
// const URL = 'http://192.9.201.87:8090/iserver/services/data-cim_shujuyuan_worksapce/rest/data'
const URL = 'http://localhost:8090/iserver/services/data-cim_shujuyuan_worksapce/rest/data'
const DataSourceName = '192_9_201_108_5432_geo_data_gis'
const Api = {
  // 供热范围数据 面数据 完成
  getDataOfCompany({ ids, fields, attributeFilter }) {
    return new Promise((resolve) => {
        let attributeFilter_ = 'SMID > 0';
        if(attributeFilter) {
          attributeFilter_ = attributeFilter;
        }
        const param = new ol.supermap.GetFeaturesBySQLParameters({
          queryParameter: {
            name: 'CompanyRegion@' + DataSourceName,
            ids: ids,
            attributeFilter: attributeFilter_,
            fields: fields
          },
          fromIndex: 0,
          toIndex: 1000,
          datasetNames: [DataSourceName + ':CompanyRegion'],
          returnFeaturesOnly: true,
        })
        new ol.supermap.FeatureService(URL).getFeaturesBySQL(param).then(res => {
          resolve(res.result.features)
        })
    });
  },
  // 供热范围数据 面数据 完成
  getDataOfGRFW({ ids, fields, attributeFilter }) {
    return new Promise((resolve) => {
      // service({
      //   baseURL: window.location.pathname,
      //   url: './files/data/grfw.json',
      //   method: 'GET',
      // }).then((res) => {
      //   resolve(res);
      // });
        let attributeFilter_ = 'SMID > 0';
        if(attributeFilter) {
          attributeFilter_ = attributeFilter;
        }
        const param = new ol.supermap.GetFeaturesBySQLParameters({
          queryParameter: {
            name: 'grfw0702@' + DataSourceName,
            ids: ids,
            attributeFilter: attributeFilter_,
            fields: fields
          },
          fromIndex: 0,
          toIndex: 1000,
          datasetNames: [DataSourceName + ':grfw0702'],
          returnFeaturesOnly: true,
        })
        new ol.supermap.FeatureService(URL).getFeaturesBySQL(param).then(res => {
          resolve(res.result.features)
        })
    });
  },
  // 供热管线数据 面数据 完成
  getDataOfGRGX({ ids, fields }) {
    return
    return new Promise((resolve) => {
      // service({
      //   baseURL: window.location.pathname,
      //   url: './files/data/grgx.json',
      //   method: 'GET',
      // }).then((res) => {
      //   resolve(res);
      // });

      const param = new ol.supermap.GetFeaturesBySQLParameters({
        queryParameter: {
          // name: 'grgx_20250321@192_9_201_108_5432_geo_data_gis',
          name: '管线汇总@' + DataSourceName,
          ids: ids,
          attributeFilter: 'SMID > 0',
          fields: fields
        },
        fromIndex: 0,
        maxFeatures: 100000,
        toIndex: -1,
        // datasetNames: ['192_9_201_108_5432_geo_data_gis:grgx_20250321'],
        datasetNames: [DataSourceName + ':管线汇总'],
        returnFeaturesOnly: true,
        hasGeometry: true
      })
      new ol.supermap.FeatureService(URL).getFeaturesBySQL(param).then(res => {
        resolve(res.result.features)
      })
    });
  },
  // 供热站 面数据 完成
  getDataOfGRZ({ ids, fields, attributeFilter, hasNotGeometry }) {
    return new Promise((resolve) => {
      // service({
      //   baseURL: window.location.pathname,
      //   url: './files/data/grz.json',
      //   method: 'GET',
      // }).then((res) => {
      //   resolve(res);
      // });
      // 涉及到的公司
      // 1 暖域
      // 2 幸福源
      // 3 青岛能源发展
      // 4 开源
      // 5 青岛家盛
      // 6 青岛龙发
      // 7 青岛新阳
      // 8 青岛中节能
      // 9 青岛海能达
      // 10 青岛兆源
      //
      let attributeFilter_ = 'SMID > 0';
      if(attributeFilter) {
        attributeFilter_ = attributeFilter;
      }
      const param = new ol.supermap.GetFeaturesBySQLParameters({
        queryParameter: {
          name: 'grgsxx@' + DataSourceName,
          ids: ids,
          attributeFilter: attributeFilter_,
          fields: fields
        },
        fromIndex: 0,
        maxFeatures: 10000,
        toIndex: -1,
        datasetNames: [DataSourceName + ':grgsxx'],
        returnFeaturesOnly: true,
        hasGeometry: !hasNotGeometry? true: false
      })
      new ol.supermap.FeatureService(URL).getFeaturesBySQL(param).then(res => {
        resolve(res.result.features)
      })

    });
  },
  // 换热站 点数据 完成
  getDataOfHRZ({ ids, fields, attributeFilter }) {
    return new Promise((resolve) => {
      let attributeFilter_ = 'SMID > 0';
      if(attributeFilter) {
        attributeFilter_ = attributeFilter;
      }
      const param = new ol.supermap.GetFeaturesBySQLParameters({
        queryParameter: {
          // name: 'xqsspcsj_hrz@192_9_201_108_5432_geo_data_gis',
          name: 'xzhrz@' + DataSourceName,
          ids: ids,
          attributeFilter: attributeFilter_,
          fields: fields
        },
        fromIndex: 0,
        maxFeatures: 10000,
        toIndex: -1,
        // datasetNames: ['192_9_201_108_5432_geo_data_gis:xqsspcsj_hrz'],
        datasetNames: [DataSourceName + ':xzhrz'],
        returnFeaturesOnly: true
      })
      new ol.supermap.FeatureService(URL).getFeaturesBySQL(param).then(res => {
        resolve(res.result.features)
      })

    });
  },
  // 检修井数据 点数据 完成
  getDataOfJXJ({ ids, fields }) {
    return new Promise((resolve) => {
      const param = new ol.supermap.GetFeaturesBySQLParameters({
        queryParameter: {
          name: '管点_检修井@' + DataSourceName,
          ids: ids,
          attributeFilter: 'SMID > 0',
          fields: fields
        },
        fromIndex: 0,
        maxFeatures: 10000,
        toIndex: -1,
        datasetNames: [DataSourceName + ':管点_检修井'],
        returnFeaturesOnly: true
      })
      new ol.supermap.FeatureService(URL).getFeaturesBySQL(param).then(res => {
        resolve(res.result.features)
      })
    });
  },
  // 阀门数据 点数据 完成
  getDataOfFAMEN({ ids, fields }) {
    return new Promise((resolve) => {
      const param = new ol.supermap.GetFeaturesBySQLParameters({
        queryParameter: {
          name: '管点_阀门@' + DataSourceName,
          ids: ids,
          attributeFilter: 'SMID > 0',
          fields: fields
        },
        fromIndex: 0,
        maxFeatures: 10000,
        toIndex: -1,
        datasetNames: [DataSourceName + ':管点_阀门'],
        returnFeaturesOnly: true
      })
      new ol.supermap.FeatureService(URL).getFeaturesBySQL(param).then(res => {
        resolve(res.result.features)
      })
    });
  },
  // 供热面积的统计 换热站
  getDataOfHRZAnalize({ fieldName }) {
    return new Promise((resolve) => {
      const param = new ol.supermap.FieldStatisticsParameters({
        datasource: DataSourceName,
        dataset: 'xzhrz',
        // fieldName: 'grjmhs',
        fieldName: fieldName,
        statisticMode: ['SUM']
      })
      new ol.supermap.FieldService(URL).getFieldStatisticsInfo(param, function (res) {
        resolve(res.result.SUM)
      })

    });
  },
  // 获取列表
  getComplainListData(data) {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/rest/complaint/list',
        method: 'POST',
        data: data
      }).then((res) => {
        resolve(res);
      });
    })
  },
  // sheet 文件上传
  uploadSheetFile(data) {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/rest/complaint/upload',
        method: 'POST',
        data: data,
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }).then(res => {
        resolve(res)
      })
    })

  },
  // 删除单个
  deleteSingleComplainInfo(params) {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/rest/complaint/delete',
        method: 'GET',
        params: params
      }).then(res => {
        resolve(res)
      })
    })
  },
  // word 的导出
  exportSingleWORDfile(params) {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/rest/complaint/export',
        method: 'GET',
        params: params,
        responseType: 'blob',
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 删除多个
  deleteMutiComplainInfo(data) {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/rest/complaint/delete/batch',
        method: 'POST',
        data: data
      }).then(res => {
        resolve(res)
      })
    })
  },
  //  word
  getComplainListDataWORD(data) {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/rest/complaint/word/list',
        method: 'POST',
        data: data
      }).then((res) => {
        resolve(res);
      });
    })
  },
  // 删除多个 word
  deleteMutiComplainWORD(data) {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/rest/complaint/word/delete/batch',
        method: 'POST',
        data: data
      }).then(res => {
        resolve(res)
      })
    })
  },
  //  回退投诉表单的状态项
  rebackComplaint(params) {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/rest/complaint/export/status',
        method: 'GET',
        params: params
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 批量回退
  mutiRebackComplaint(data) {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/rest/complaint/batch/export/status',
        method: 'POST',
        data: data
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 换热站相关的 token 请求
  getTokenOfHeating() {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/api/out/service/getToken',
        method: 'GET',
        params: {
          userName: 'root',
          passWord: '1w23lyc45j'
        }
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取热源站的实时数据
  getImDataOfHeatSource(data, token) {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/api/heating/list',
        method: 'GET',
        params: data,
        headers: {
          'token': token
        }
      }).then(res => {
        resolve(res)
      })
    })
  },
  // 获取换热站的实时数据
  getImDataOfHeatExchange(data) {
    return new Promise(resolve => {
      service({
        baseURL: window.location.pathname,
        url: '/api/heatexchange/list',
        method: 'GET',
        params: data
      }).then(res => {
        resolve(res)
      })
    })
  }
};
window.Api = Api;
export default Api;
